#!/bin/awk -f
### SYNOPSIS: initinst TILING NU,m,n ...
### initializes n of NU-type nodes to instance m.
BEGIN{
  f="INPUT/objects.def";
  getline < f;
  getline < f;
  nuofs=$1;
  close(f);
  ttvl=-100;
  if(ARGC==1||ARGV[1]=="-h"){
    print "Synopsis: initinst TILING NU,m,n ...";
    print "    --  initializes n of NU-type nodes to instance m.";
    exit
  }
  while(ARGC>2){
    split(ARGV[ARGC-1],a,",");
    for(i=1;i<=a[3];i++){
      n[a[1]]++;
      ist[a[1],n[a[1]]]=a[2];
    }
    delete ARGV[ARGC-1]; ARGC--;
  }
}
FNR<3
FNR==3{print $0" read_flags"}
FNR>3{
  nn++;
  s=0; s+=($1+$2+$3+$4+$5);
  s-=nuofs;
  s=s%5;
  if(s>2)s-=5;
  m[s]++;
  x=ttvl;
  if(ist[s,m[s]]!="")x=ist[s,m[s]];
  print $1,$2,$3,$4,$5,"  ",x," "nn," nu="s;
}
END{}
